FROM daocloud.io/centos:6
MAINTAINER xujif <i@xujif.com>
RUN echo "nameserver 8.8.8.8" >>/etc/resolv.conf
RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
RUN curl http://mirrors.aliyun.com/repo/Centos-6.repo > /etc/yum.repos.d/Centos-6.repo 
RUN rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
RUN rpm -Uvh http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
RUN yum install -y nginx fontconfig php56w php56w-fpm php56w-mbstring php56w-gd php56w-dom php56w-pdo php56w-mysqlnd
RUN chkconfig nginx on && chkconfig nginx on
RUN echo -e "server {		          \n\
		listen       80;		          \n\
		server_name  localhost;	          \n\
		root   /data/weixin-fetch/public/;              \n\
		location / {			          \n\
			try_files \$uri \$uri/ /index.php?\$query_string;	          \n\
			index index.php;	          \n\
		}						          \n\
		location ~ .+\.php(\$|/) {	          \n\
			fastcgi_pass  127.0.0.1:9000;          \n\
			fastcgi_index  index.php;          \n\
			fastcgi_split_path_info ^(.+\.php)(/.*)\$;          \n\
			fastcgi_param PATH_INFO \$fastcgi_path_info;          \n\
			fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;          \n\
			fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info;          \n\
			include fastcgi_params;          \n\
	   }          \n\
	}" >/etc/nginx/conf.d/default.conf
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer
VOLUME /data
WORKDIR /data
EXPOSE 80
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
ADD id_rsa /root/.ssh/id_rsa
RUN yum install -y git
RUN echo "StrictHostKeyChecking no" >>/etc/ssh/ssh_config
RUN echo -e 'mkdir /data/weixin-fetch						   \n\
		cd /data/weixin-fetch 								   \n\
		git clone git@git.oschina.net:xujif/weixin-fetch.git . \n\
		git pull											   \n\
		chmod a+x ./phantomjs  								   \n\
		rm -f .env			   								   \n\
		cp .env.example .env  	 							   \n\
		sed -i -e "s/\DB_HOST=\(.*\)/DB_HOST=${DB_HOST}/" -e "s/\DB_DATABASE=\(.*\)/DB_DATABASE=${DB_DATABASE}/" -e "s/\DB_PASSWORD=\(.*\)/DB_PASSWORD=${DB_PASSWORD}/" -e "s/\DB_USERNAME=\(.*\)/DB_USERNAME=${DB_USERNAME}/"  .env 	\n\
		composer dump-autoload  							   \n\
		php artisan optimize  								   \n\
		php artisan key:gen  								   \n\
		php artisan migrate --seed							   \n\
		chown -R apache:apache . 							   \n\
		service php-fpm start								   \n\
		nginx'>/root/start.sh
CMD sh /root/start.sh

